home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 17 / Computer Interactive cdrom 17 - gen 99.iso / ZDNETIT / CONTENT / SMTPCEMS.ZIP / MFC_PGM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-12  |  3.8 KB  |  157 lines

  1. //
  2. //   MFC_PGM.CPP [edit EMAIL.H before compiling]
  3. //
  4. //   MFC_PGM is intended as a simple example of the use of
  5. //   the Microsoft Foundation Class (MFC) library with the
  6. //   SMTP/POP3 Email Engine for C/C++ (SEE4C).
  7. //   
  8. //   This example emails a simple message.
  9. //
  10. //   Edit EMAIL.H and SEND_TO, SUBJECT, and MESSAGE (line 97 below)
  11. //   before compiling.
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "resource.h"
  16.  
  17. #include "see.h"
  18. #include "mfc_pgm.h"
  19.  
  20. static CWnd * MainWndPtr;
  21.  
  22. // CMainWindow: constructor
  23.  
  24. CMainWindow::CMainWindow()
  25. {int Row;
  26.  CString s = "WSC Test";
  27.  LoadAccelTable( "MainAccelTable" );
  28.  Create( NULL, "MFC Example Program",
  29.       WS_OVERLAPPEDWINDOW, rectDefault, NULL, "MainMenu" );
  30.  for(Row=0;Row<NROWS;Row++) Buffer[Row].Empty;
  31.  TheRow = 0;
  32. }
  33.  
  34. // Display character on screen
  35.  
  36. void CMainWindow::DisplayChar(int nChar)
  37. {int Row;
  38.  // process the character
  39.  if(nChar==10) return;
  40.  if(nChar==13)
  41.    {if(TheRow<NROWS-1) TheRow++;
  42.     else
  43.       {// scroll page (TheRow==NROWS-1)
  44.        for(Row=0;Row<=NROWS-2;Row++) Buffer[Row] = Buffer[Row+1];
  45.        Buffer[NROWS-1].Empty();
  46.        TheRow = NROWS-1;
  47.       }
  48.    }
  49.  else
  50.    {// stuff character into display buffer
  51.     Buffer[TheRow] += (char)nChar;
  52.    }
  53. }
  54.  
  55. // Display string on screen
  56.  
  57. void CMainWindow::DisplayLine(CString Text)
  58. {
  59.  Buffer[TheRow] += Text;
  60.  DisplayChar(13);
  61.  Invalidate(TRUE);
  62. }
  63.  
  64. // CMainWindow message map
  65.  
  66. BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
  67.    //{{AFX_MSG_MAP( CMainWindow )
  68.    ON_WM_PAINT()
  69.    ON_COMMAND(ID_EXIT,    PgmExit)
  70.    ON_COMMAND(ID_SEND,    PgmSend)
  71.    //}}AFX_MSG_MAP
  72. END_MESSAGE_MAP()
  73.  
  74. CTheApp NEAR theApp;
  75.  
  76. // PgmExit: Exits application
  77.  
  78. void CMainWindow::PgmExit(void)
  79. {
  80.  PostQuitMessage(0);
  81. }
  82.  
  83. // display error message 
  84.  
  85. void CMainWindow::ShowError(int Code)
  86. {static char Buffer[65];
  87.  static char Temp[90];
  88.  seeErrorText(Code,(LPSTR)Buffer,65);
  89.  wsprintf((LPSTR)Temp,"SEE Error %d: %s\n", Code, (LPSTR)Buffer);
  90.  DisplayLine((LPSTR)Temp);
  91. }
  92.  
  93. // PgmSend : Send email
  94. void CMainWindow::PgmSend(void)
  95. {int Code;
  96.  
  97. #include "email.h"
  98. #define SEND_TO   "<msc@traveller.com>"
  99. #define SUBJECT   "Email from MFC_PGM"
  100. #define MESSAGE   "This is a test.\r\n\r\n--Mike"
  101.  
  102.  // connect to SMTP server 
  103.  DisplayLine("Connecting...");
  104.  Code = seeSmtpConnect(
  105.      (LPSTR)SMTP_HOST_NAME,                       // SMTP server 
  106.      (LPSTR)YOUR_EMAIL_ADDR,                      // return email address  
  107.      (LPSTR)NULL);                                // Reply-To header   
  108.  if(Code<0) 
  109.    {ShowError(Code); 
  110.     return;
  111.    }
  112.  // send email 
  113.  DisplayLine("Sending mail...");
  114.  Code = seeSendEmail(
  115.      (LPSTR)SEND_TO,                              // To list 
  116.      (LPSTR)NULL,                                 // CC list
  117.      (LPSTR)NULL,                                 // BCC list 
  118.      (LPSTR)SUBJECT,                              // subject 
  119.      (LPSTR)MESSAGE,                              // message text 
  120.      (LPSTR)NULL);                                // MIME attachment                 
  121.  if(Code<0) 
  122.    {ShowError(Code); 
  123.     return;
  124.    }
  125.  DisplayLine("Closing...");
  126.  Code = seeClose();
  127.  Invalidate(TRUE);
  128. }
  129.  
  130. // OnPaint:
  131.  
  132. void CMainWindow::OnPaint()
  133. {int Row;
  134.  CPaintDC dc( this );
  135.  CRect rect;
  136.  GetClientRect( rect );
  137.  dc.SetTextAlign( TA_BASELINE | TA_LEFT );
  138.  dc.SetTextColor( ::GetSysColor( COLOR_WINDOWTEXT ) );
  139.  dc.SetBkMode(TRANSPARENT);
  140.  dc.SelectStockObject(ANSI_FIXED_FONT);
  141.  for(Row=0;Row<=TheRow;Row++)
  142.    {// display the row
  143.     dc.TextOut( 4, 16+(Row<<4), Buffer[Row], Buffer[Row].GetLength() );
  144.    }
  145. }
  146.  
  147. // InitInstance:
  148.  
  149. BOOL CTheApp::InitInstance()
  150. {SetDialogBkColor(); //hook gray dialogs
  151.  m_pMainWnd = new CMainWindow();
  152.  m_pMainWnd->ShowWindow( m_nCmdShow );
  153.  m_pMainWnd->UpdateWindow();
  154.  MainWndPtr = m_pMainWnd;
  155.  return TRUE;
  156. }
  157.